
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep

# 指定chromedriver路径（137版本）
driver_path = "D:\\pycharm\\PM_test\\chromedriver.exe"

# 创建WebDriver实例
service = Service(driver_path)
options = Options()
browser = webdriver.Chrome(service=service, options=options)
browser.maximize_window()
wait = WebDriverWait(browser, 10)
# 登录函数
def login():
    browser.get("http://146.56.217.9:9131")
    browser.find_element(By.ID, "username").send_keys("admin_9131")
    browser.find_element(By.ID, "password").send_keys("admin")
    browser.find_element(By.CLASS_NAME, "button").click()
def batch_number_search():
    # 跳转至批号序列号
    browser.find_element(By.ID, "mainmenutd_products").click()
    browser.find_element(By.CSS_SELECTOR, ".menu_contenu_product_stock_productlot_list .vsmenu").click()
    #产品
    browser.find_element(By.CSS_SELECTOR,"select#search_fk_product>option:nth-child(2)").click()
    #批号/序列号
    browser.find_element(By.NAME,"search_batch").send_keys("001")
    #销售日期
    browser.find_element(By.ID,"search_sellby_dtstart").send_keys("2025/06/10")
    browser.find_element(By.ID,"search_sellby_dtend").send_keys("2025/06/12")

    #保质期
    browser.find_element(By.ID, "search_eatby_dtstart").send_keys("2025/06/10")
    browser.find_element(By.ID, "search_eatby_dtend").send_keys("2025/07/01")
    #搜索按钮
    browser.find_element(By.NAME,"button_search_x").click()
if __name__ == '__main__':
        try:
            login()
            sleep(1)  # 等待页面加载
            batch_number_search()
        except Exception as e:
            print("发生错误：", e)
        finally:
            sleep(1)
            browser.quit()
